<?php

namespace app\admin\model\aps;

use think\Model;

class Procedurestate extends Model
{
    // 表名
    protected $name = 'aps_procedurestate';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'state_text'
    ];
    

    
    public function getStateList()
    {
        return ['0' => __('State 0'),'1' => __('State 1'),'2' => __('State 2')];
    }     


    public function getStateTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function planlog()
    {
        return $this->belongsTo('Planlog', 'planlog_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function procedure()
    {
        return $this->belongsTo('Procedure', 'procedure_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
